package com.nh.action;

import java.util.List;

import com.nh.entity.GKLDictionary;

public class GKLDictionaryAction extends BaseAction {
	// 字典类型 0:嘉友计划 1：公司首页
	private int dictionaryType;

	private GKLDictionary dictionary;

	public String dictionaryAdd() {
		List<GKLDictionary> dictionarys = this.getBaseService().findByProperty("infoKey", getInfoTitle(), GKLDictionary.class);
		if (dictionarys.size() > 0) {
			dictionary = dictionarys.get(0);
		} else {
			dictionary = new GKLDictionary();
			dictionary.setInfoKey(getInfoTitle());
		}
		return "dictionaryAdd";
	}

	public String dictionarySave() {
		if (null == dictionary.getId()) {
			this.getBaseService().save(dictionary);
		} else {
			this.getBaseService().saveOrUpdate(dictionary, GKLDictionary.class);
		}
		return dictionaryAdd();
	}

	public int getDictionaryType() {
		return dictionaryType;
	}

	public void setDictionaryType(int dictionaryType) {
		this.dictionaryType = dictionaryType;
	}

	public GKLDictionary getDictionary() {
		return dictionary;
	}

	public void setDictionary(GKLDictionary dictionary) {
		this.dictionary = dictionary;
	}

	public String getInfoTitle() {
		String temp = "";
		switch (dictionaryType) {
		case 0:
			temp = "嘉友计划";
			break;
		case 1:
			temp = "公司首页";
			break;

		default:
			break;
		}
		return temp;
	}

}
